﻿(function () {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();

//Popup Login
$(document).ready(function () {
    $(".pluginButtonLabel").text("Olala");
    //Chỉ nhập số (number) vào input
    $(".number").keypress(function (e) {
        if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
            return false;
        }
    });
    $('img').attr('onerror', 'this.src=\'/Images/System/no_image.gif\'');
    $('.log').click(function () {
        $("#LOGIN").slideToggle();
    });
    $('#closePopLogin').click(function () {
        $("#LOGIN").slideUp();
    });
    $('.userIn').hover(
        function () { $('.menu_user').slideDown("fast"); },
        function () { $('.menu_user').slideUp("fast"); }
    );
    // To top
    $(window).scroll(function () {
        if ($(this).scrollTop() != 0) {
            $('.to_top').fadeIn();
        } else {
            $('.to_top').fadeOut();
        }
    });
    $('.to_top').click(function () {
        $('body,html').animate({ scrollTop: 0 }, 800);
    });
    //
    $('#search_quick').click(function () {
        var strKeyWord = $('#txtKeyword').val();
        window.location.href = "/tim-kiem?q=" + strKeyWord;
    });
    //Login=================================================
    $('#btn-login-users').click(function () {
        xLoginUsers();
    });

    //
    ClickGopY();
    xCheckPage();
    //
    var currentDate = new Date();
    $(".date").datepicker({ dateFormat: 'dd/mm/yy' });
    $(".date").datepicker("setDate", currentDate);
    //
    /*======QUẢNG CÁO 2 BÊN================*/
    MainContentW = 1000;
    LeftBannerW = 125;
    RightBannerW = 125;
    LeftAdjust = 5;
    RightAdjust = 5;
    TopAdjust = 50;
    ShowAdDiv();
    $(window).resize(function () {
        //$("#log").append("<div>Handler for .resize() called.</div>");
        ShowAdDiv();
    });
    /*=====================================*/
    $("#txtEmail, #txtMatKhau").keypress(function (e) {
        if (e.which == 13) {
            xLoginUsers();
            return false;
        }
    });

    /*------Menu chird tin tức------*/
    $("#news-P").hover(function () {
        $('.chird-tintuc').show();
    }, function () {
        $('.chird-tintuc').hide();
    });

});

// Popup Up click Góp ý
function ClickGopY() {
    $("#feedback").colorbox({
        iframe: true
    , innerWidth: 505
    , innerHeight: 470
    , opacity: 0.2
    , title: "<img src='/Images/System/feedback-icon-big.png' width='25' height='25' />" + "   " + "Gửi phản hồi."
    , href: "/default-Popup.aspx?mo=gop-y-them-moi"
    });
}

//Load Login Success
function OnSuccess(response) {
    var strResult = response.d;
    if ($.isNumeric(strResult)) {
        window.location.href = "/";
    } else {
        $('#notifition .msg-page').text(strResult);
    }
}

//thư viện của facebook
(function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=468794623180533";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

/*=====================liblary function================================*/
jQuery.fn.errorItem = function (message) {
    $(this).addClass("error-item");
    $(this).attr("placeholder", message);
};
/*=====================================================================*/

//Goto Error
jQuery.fn.goToError = function () {
    $('html,body').animate({ scrollTop: ($("#notifition").offset().top - 10) }, 'slow');
};

//LOAD DANH SACH HANG SO
function xGetHangSo(tv_id, type) {
    $.ajax({
        type: "POST",
        url: "/Default.aspx/fncGetHangSo_ByID",
        data: '{TV_ID: "' + tv_id + '"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            var Data = response.d;
            switch (type) {
                case 'huong-dan':
                    $(".huong-dan").html(Data);
                    break;
                case 'tai-sao':
                    $(".tai-sao").html(Data);
                    break;
                default:
                    $(".tai-sao").html("");
                    break;
            }
        },
        failure: function (response) {
            //alert("failure: " + response.d);
        },
        error: function (response) {
            //alert("error: " + response.d);
        }
    });
}

// Check page add css menu
function xCheckPage() {
    var intCount = 0;
    $(".menu_nav a").each(function () {
        var strUrl = $(this).attr("href");
        var strControl = $(".hd_Control").val();
        if (strUrl.indexOf(strControl) == 1) {
            $(this).addClass("nav-active");
            intCount++;
        }
    });
    if (intCount == 0) $(".menu_nav a:first").addClass("nav-active");
}

// Check định dạng Email
function xfomatEmail(email) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\ ".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}

//===========================================================================================================================
function FloatTopDiv() {
    startLX = ((document.body.clientWidth - MainContentW) / 2) - LeftBannerW - LeftAdjust, startLY = TopAdjust + 80;
    startRX = ((document.body.clientWidth - MainContentW) / 2) + MainContentW + RightAdjust, startRY = TopAdjust + 80;
    var d = document;
    function ml(id) {
        var el = d.getElementById ? d.getElementById(id) : d.all ? d.all[id] : d.layers[id];
        el.sP = function (x, y) { this.style.left = x + 'px'; this.style.top = y + 'px'; };
        el.x = startRX;
        el.y = startRY;
        return el;
    }
    function m2(id) {
        var e2 = d.getElementById ? d.getElementById(id) : d.all ? d.all[id] : d.layers[id];
        e2.sP = function (x, y) { this.style.left = x + 'px'; this.style.top = y + 'px'; };
        e2.x = startLX;
        e2.y = startLY;
        return e2;
    }
    window.stayTopLeft = function () {
        if (document.documentElement && document.documentElement.scrollTop)
            var pY = document.documentElement.scrollTop;
        else if (document.body)
            var pY = document.body.scrollTop;
        if (document.body.scrollTop > 30) { startLY = 3; startRY = 3; } else { startLY = TopAdjust; startRY = TopAdjust; };
        ftlObj.y += (pY + startRY - ftlObj.y) / 16;
        ftlObj.sP(ftlObj.x, ftlObj.y);
        ftlObj2.y += (pY + startLY - ftlObj2.y) / 16;
        ftlObj2.sP(ftlObj2.x, ftlObj2.y);
        setTimeout("stayTopLeft()", 1);
    }
    ftlObj = ml("divAdRight");
    //stayTopLeft();
    ftlObj2 = m2("divAdLeft");
    stayTopLeft();
}
function ShowAdDiv() {
    var objAdDivRight = document.getElementById("divAdRight");
    var objAdDivLeft = document.getElementById("divAdLeft");
    if (document.body.clientWidth < 1250) {
        objAdDivRight.style.display = "none";
        objAdDivLeft.style.display = "none";
    }
    else {
        objAdDivRight.style.display = "block";
        objAdDivLeft.style.display = "block";
        FloatTopDiv();
    }
}
function xLoginUsers() {
    $('#notifition').slideDown();
    $('#notifition .msg-page').text('Đang đăng nhập...');
    $.ajax({
        type: "POST",
        url: "/Default.aspx/fncLogin",
        data: '{strEmail: "' + $('#txtEmail').val() + '"'
        + ',strPassword: "' + $('#txtMatKhau').val() + '"'
        + '}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        failure: function (response) {
            //alert("failure: " + response.d);
        },
        error: function (response) {
            //alert("error: " + response.d);
        }
    });
}